package Z03JiHeKuangJia.ArrayListStudy.T02JHMethod;

import sun.security.timestamp.TSRequest;

import java.util.ArrayList;

public class JHutil {
    public static void main(String[] args) {
        ArrayList heros = new ArrayList();

        for (int i = 0; i < 5;i++){
            heros.add(new Hero("hero" + i));
        }
        System.out.println(heros);
        Hero speciaHero = new Hero("special hero");
        heros.add(3,speciaHero);
        System.out.println(heros.toString());
        System.out.print("虽然一个新的对象名字也叫 hero 1，但是contains的返回是:");
        System.out.println(heros.contains(new Hero("hero 1")));
        System.out.print("而对specialHero的判断，contains的返回是:");
        System.out.println(heros.contains(speciaHero));


        System.out.println(heros.get(5));
        // 超出范围报错
        //System.out.println(heros.get(6));

        System.out.println("specialHero所处的位置 ：" + heros.indexOf(speciaHero));
        System.out.println("新的英雄名字是s的位置：" + heros.indexOf(new Hero("S")));

        System.out.println(heros);
        heros.remove(2);
        System.out.println(heros);
        heros.remove("S");

        System.out.println(heros);
        heros.set(3,new Hero("A"));
        System.out.println(heros);

        System.out.println(heros.size());


        System.out.println(heros);

        Hero hs[] = (Hero[]) heros.toArray(new Hero[]{});
        System.out.println("数组：" +hs );


        System.out.println(heros);
        ArrayList anotherHeros = new ArrayList();
        anotherHeros.add(new Hero("yrooooot"));
        anotherHeros.add(new Hero("yrrfffrt"));
        anotherHeros.add(new Hero("yrriiiirt"));
        System.out.println(anotherHeros);

        System.out.println(anotherHeros);
        System.out.println(heros);

        heros.addAll(anotherHeros);
        System.out.println(heros);


        System.out.println(heros);
        heros.clear();
        System.out.println(heros);



    }
}

class Hero{
    public String name;
    public float hp;

    public int damage;
    // 数组的局限性
    public Hero(){


    }

    public Hero(String name){
        this.name = name;
    }

    public String toString(){
        return name;
    }
}